<?php

namespace app\store\model;

use app\common\model\UserCoupon as UserCouponModel;

/**
 * 用户优惠券模型
 * Class UserCoupon
 * @package app\store\model
 */
class UserCoupon extends UserCouponModel
{
    /**
     * 获取优惠券列表
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList()
    {   
        // 城市
        $where = [];
        if (self::$region['province'] > 0 && self::$region['city'] > 0) {
            $where = ['province_id' => self::$region['province'], 'city_id' => self::$region['city']];
        }
        return $this->with(['user','coupon'])
            ->alias('user_coupon')
            ->join('coupon','coupon.coupon_id = user_coupon.coupon_id')
            ->where($where)
            ->order(['user_coupon.create_time' => 'desc'])
            ->paginate(15, false, [
                'query' => request()->request()
            ]);
    }

}